/**  
 * @Title:  PropUtils.java
 * @Package com.hugedata.dataplatform.cdn.util
 * @Description: TODO(用一句话描述该文件做什么)
 * @author wangxiaoming
 * @date  Nov 3, 2014 3:59:31 PM
 * @version V1.0  
 * Update Logs:
 * ****************************************************
 * Name:
 * Date:
 * Description:
 ******************************************************
 */
package com.hugedata.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.zookeeper.common.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName: PropUtils
 * @Description: properties文件加载工具类
 * @author wangxiaoming
 * @date Nov 3, 2014 3:59:31 PM
 * 
 */
public class PropUtils
{
    private static final Logger LOGGER = LoggerFactory
            .getLogger(PropUtils.class);
    
    private static Properties configProp;
    
    /**
     * 
     * @Title: getProperties
     * @Description: 将文件加载到Properties中并返回
     * @author wangxiaoming
     * @param fileName
     * @return
     * @throws
     */
    public static Properties getProperties(String fileName)
    {
        Properties prop = new Properties();
        InputStream is = PropUtils.class.getClassLoader().getResourceAsStream(
                fileName);
        try
        {
            prop.load(is);
        }
        catch (IOException e)
        {
            LOGGER.error("parse {} exception", fileName, e);
            System.exit(-1);
        }
        finally
        {
            IOUtils.closeStream(is);
        }
        return prop;
    }
    
    static
    {
        configProp = getProperties("config.properties");
    }
    
    public static String getProp(String fieldName)
    {
        return configProp.getProperty(fieldName);
    }
}
